﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Helpers;

namespace Helpers.Tools
{
    public class InvokationInfo
    {
        public const string ERR = "ERR";
        public const string EXC = "EXC";
        public const string INF = "INF";
        public const string WRN = "WRN";



        public List<string> ErrorMessages { get; set; }
        public List<string> WarningMessages { get; set; }
        public List<string> InfoMessages { get; set; }
        public List<string> ExceptionMessages { get; set; }



        public InvokationInfo()
        {
            Clear();
        }



        public virtual void Clear()
        {
            ErrorMessages = new List<string>();
            WarningMessages = new List<string>();
            InfoMessages = new List<string>();
            ExceptionMessages = new List<string>();
        }



        public virtual void AddException(string exception)
        {
            AddRecord(exception, EXC);
        }

        public virtual void AddError(string error)
        {
            AddRecord(error, ERR);
        }

        public virtual void AddWarning(string warning)
        {
            AddRecord(warning, WRN);
        }

        public virtual void AddInfo(string info)
        {
            AddRecord(info, INF);
        }

        public virtual void AddRecord(string record, string type)
        {
            if (type == EXC)
            {
                ExceptionMessages.Add(record);
                if (LogHelper.Log != null)
                    LogHelper.Log.Fatal(record);
            }
            else if (type == ERR)
            {
                ErrorMessages.Add(record);
                if (LogHelper.Log != null)
                    LogHelper.Log.Error(record);
            }
            else if (type == WRN)
            {
                WarningMessages.Add(record);
                if (LogHelper.Log != null)
                    LogHelper.Log.Warn(record);
            }
            else if (type == INF)
            {
                ErrorMessages.Add(record);
                if (LogHelper.Log != null)
                    LogHelper.Log.Info(record);
            }
            else
                AddRecordInternal(record, type);
        }

        protected virtual void AddRecordInternal(string record, string type)
        {
            throw new Exception(string.Format("Record '{0}' was wrote with unknown type : '{1}'", record, type));
        }
    }


}
